package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCLogin {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()){

            Scanner sc = new Scanner(System.in);
            System.out.println("请输入账号: ");
            String username = sc.nextLine();
            System.out.println("请输入密码: ");
            String password = sc.nextLine();

            Statement statement = connection.createStatement();
            String sql = "select nickname from userinfo where username='"+username+"' and password='"+password+"'";
            ResultSet r = statement.executeQuery(sql);
            if(r.next()){
                System.out.println("登录成功, 欢迎回来, "+r.getString("nickname"));
            }else {
                System.out.println("登录失败, 账号或密码错误");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
